import Vue from 'vue';

export default {
    requestUserInfo: function (context, payload) {
        return new Promise(function (resolve, reject) {
            Vue.prototype.$api.userApi.getUserInfo({ id: payload }).then(res => {
                if (res.code === 2010) {
                    context.commit('overRideValue', {
                        state: 'userInfo',
                        value: res.data
                    }); // 存储用户信息
                    Vue.prototype.$api.educationApi
                        .getEduInfo({ id: payload })
                        .then(res => {
                            const eduData = res.code === 10002 ? res.eduInfo : {};
                            context.commit('overRideValue', {
                                state: 'educationInfo',
                                value: eduData
                            }); // 存储教育信息
                            resolve(true);
                        })
                        .catch(err => {
                            reject(err);
                        });
                } else {
                    // eslint-disable-next-line prefer-promise-reject-errors
                    reject(false);
                }
            });
        });
    }
};
